﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HaumDisplay
{
    class ShapeTools
    {
        public static double GetRotate(PointF center, PointF p)
        {
            // 计算向量的 x 和 y 分量
            float dx = p.X - center.X;
            float dy = p.Y - center.Y;
            // 使用 Math.Atan2 函数计算角度（弧度）
            double angleRad = Math.Atan2(dy, dx);
            // 将弧度转换为角度
            float angleDeg = (float)(angleRad * (180 / Math.PI));
            return angleDeg;
        }

        public static PointF RotatePoint(PointF point, PointF center, double angle) {
            // 将角度转换为弧度
            double radians = angle * (float)(Math.PI / 180);
            float cosAngle = (float)Math.Cos(radians);
            float sinAngle = (float)Math.Sin(radians);

            // 计算平移到原点后的坐标
            float translatedX = point.X - center.X;
            float translatedY = point.Y - center.Y;

            // 进行旋转操作
            float rotatedX = translatedX * cosAngle - translatedY * sinAngle;
            float rotatedY = translatedX * sinAngle + translatedY * cosAngle;

            // 平移回原来的位置
            float newX = center.X + rotatedX;
            float newY = center.Y + rotatedY;

            return new PointF(newX, newY);
        }

    }
}
